home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fatted Calf
/
The Fatted Calf.iso
/
Demos
/
ByCompany
/
ActiveIngredients
/
communicae
/
communicae.app
/
DemoFiles
/
communicae-mouse.el
< prev
next >
Wrap
Lisp/Scheme
|
1993-09-21
|
3KB
|
100 lines
;; communicae-mouse.el
;; Active Ingredients, Inc. 1990
;; Allow the Command+key combinations to work:
(setq meta-flag t)
;; Make mouse clicks in Communicae move the point to the cursor.
;; "send mouse clicks" must also be turned on in the Emulation panel.
;;
;; This version is very simple. It would be nice to make double/triple
;; clicks and drags select regions, and shift flags do cut/paste. It
;; may also be nice to make clicks in completion lists copy the word
;; into the minibuffer. If you would like to make such
;; changes, the args are:
;;
;; (nth 0 args) - screen row (starting at 1)
;; (nth 1 args) - screen column (starting at 1)
;; (nth 2 args) - bit flags:
;; 0xF - 0 = drag, 1 = single click, 2 = double, etc.
;; 16 - Alpha lock or Shift
;; 32 - Shift
;; 64 - Control
;; 128 - Alternate
;; 256 - Command
(defun screen-pos-to-window (x y)
"Find window corresponding to screen coordinates.
X and Y are 0-based character positions on the screen."
(let ((edges (window-edges))
(window nil))
(while (and (not (eq window (selected-window)))
(or (< y (nth 1 edges))
(>= y (nth 3 edges))
(< x (nth 0 edges))
(>= x (nth 2 edges))))
(setq window (next-window window))
(setq edges (window-edges window))
)
(or window (selected-window))
)
)
(defun mouse-handle (args)
"Handles Communicae mouse press"
(let*
((y (- (nth 0 args) 1))
(x (- (nth 1 args) 1))
window edges)
(if (eq (logand (nth 2 args) 15) 0)
(setq window (selected-window))
(setq window (screen-pos-to-window x y))
(select-window window))
(setq edges (window-edges window))
(setq x (- x (nth 0 edges)))
(setq y (- y (nth 1 edges)))
(cond ((>= y (- (nth 3 edges) (nth 1 edges) 1))
(scroll-up 1)
(move-to-window-line -1))
((>= y 0)
(move-to-window-line y))
(t (scroll-down 1) (move-to-window-line 0)))
(move-to-column x)
))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; This code makes Emacs parse the ^[[ sequences produced by ANSI
;; terminals, and then do something intelligent based on the last
;; character. Currently it recognizes the H for the mouse clicks,
;; and inserts all other characters.
;; If send-8-bits is turned on, a M-^[ is sent (not a M-[ as you
;; might expect). This conflicts with the eval command. It also
;; means that M-[ does eval, but M-[ does nothing by default.
(defun read-arg-list ()
"Read a #;#;#X list as produced by ANSI terminals. Returns the list
of numbers and the terminating character."
(let*
((args (list 0)) (char (read-char)))
(while (< char ?@)
(if (and (>= char ?0) (<= char ?9))
(rplaca args (+ (* (car args) 10) (- char ?0))))
(if (eq char ?\;) (setq args (cons 0 args)))
(setq char (read-char))
)
(cons (nreverse args) char)))
(defun csi-handle ()
"Handles terminal ^[[ sequences, does eval-expression if you type Esc-Esc"
(interactive)
(if (input-pending-p)
(let*
((args (read-arg-list)) (code (cdr args)) (args (car args)))
(cond
((= code ?H) (mouse-handle args))
(t (insert-char code 1))))
(command-execute 'eval-expression)))
(global-set-key "\M-[" 'csi-handle)
(global-set-key "\233" 'csi-handle)